package com.only4play.productcenter.infrastructure.convert;

import com.only4play.productcenter.api.constants.ProductType;

import javax.persistence.AttributeConverter;

public class ProductTypeConverter implements AttributeConverter<ProductType,Integer> {

  @Override
  public Integer convertToDatabaseColumn(ProductType productType) {
    return productType.getCode();
  }

  @Override
  public ProductType convertToEntityAttribute(Integer code) {
    return ProductType.of(code).orElse(null);
  }
}
